package com.lifeonwalden.game.mindustry.entity;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.lifeonwalden.game.mindustry.Global;
import com.lifeonwalden.game.mindustry.constant.League;
import com.lifeonwalden.game.mindustry.constant.SurfaceType;
import com.lifeonwalden.game.mindustry.constant.Toward;
import com.lifeonwalden.game.mindustry.feature.TextureUnit;
import com.lifeonwalden.game.mindustry.world.Coordinate;

/**
 * surface unit
 */
public class Surface implements TextureUnit, Cloneable {
    // storage count
    public float count;
    public SurfaceType type;
    public boolean destroyed = false;
    public Toward toward = Toward.UP;
    public League league;
    public short hp;

    // coordinate
    public short x, y;

    @Override
    public short x() {
        return this.x;
    }

    @Override
    public short y() {
        return this.y;
    }

    @Override
    public void x(short x) {
        this.x = x;
    }

    @Override
    public void y(short y) {
        this.y = y;
    }

    @Override
    public TextureRegion texture() {
        return this.type.texture;
    }

    @Override
    public void doJobBefore() {
    }

    @Override
    public void draw(Batch batch) {
        batch.draw(this.type.texture, this.x, this.y);
    }

    @Override
    public void doJobAfter() {
        if (hp < 0) {
            this.destroyed = true;
            this.destroy();
            Global.world.removeUnit(new Coordinate(this.x, this.y));
        }
    }

    public void destroy() {

    }

    public Surface copy(boolean deep) {
        try {
            return (Surface) clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
